import user from "@/common/user.js"
import http from "@/common/http.js"

// POST /api/v1/getCommodityList 获取我的机具接口
function getOrderList(page, startDate, endDate, call) {
	user.getSign(secret => {
		let date = new Date();
		let data = {
			"current": page,
			"size": 20,
			"secret": secret,
			"startDate": startDate, // 格式 2022-04-06
			"endDate": endDate, // 格式 2022-04-06
			"userId": user.getUserId(),
			"boundStatus": 1,
		}

		http.request({
			url: '/api/v1/getOrderList',
			data: data,
			success: ret => {
				call(ret);
			},
			fail: ret => {
				console.log(ret);
				uni.showToast({
					icon: 'error',
					title: '获取订单信息失败'
				})
			}
		})

	})


}

function getTeamOrderList(page, startDate, endDate, call) {
	user.getSign(secret => {
		let date = new Date();
		let data = {
			"current": page,
			"size": 20,
			"secret": secret,
			"startDate": startDate, // 格式 2022-04-06
			"endDate": endDate, // 格式 2022-04-06
			"userId": user.getUserId(),
			"boundStatus": 1,
		}

		http.request({
			url: '/api/v1/getTeamOrderList',
			data: data,
			success: ret => {
				call(ret);
			},
			fail: ret => {
				console.log(ret);
				uni.showToast({
					icon: 'error',
					title: '获取订单信息失败'
				})
			}
		})
	})
}


function getOrderAmount(call) {
	user.getSign(secret => {
		http.request({
			url: '/api/v1/statOrderAmount',
			data: {
				"endDate": "",
				"secret": secret,
				"startDate": "",
				"userId": user.getUserId()
			},
			success: ret => {
				call(ret);
			},
			fail: ret => {
				uni.showToast({
					icon: 'error',
					title: '获取订单信息失败'
				})
			}
		})
	})

}

export default {
	getOrderAmount: getOrderAmount,
	getOrderList: getOrderList,
	getTeamOrderList: getTeamOrderList,
}
